﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartSpace.Workflow;

namespace SmartSpace.OA
{
    public class LeaveRequestUpdater : IBizDataUpdater
    {
        public ServiceResult Update(InstanceState state)
        {
            using (OADbContext context = new OADbContext())
            {
                LeaveRequest request = context.Set<LeaveRequest>().Where(p => p.Id == state.RefId).SingleOrDefault();
                request.StatusCode = state.StatusCode;
                request.StatusText = state.StatusText;
                context.Entry(request).State = System.Data.Entity.EntityState.Modified;
                if (context.SaveChanges() > 0)
                {
                    return new ServiceResult(true);
                }
                return new ServiceResult(false);
            }
        }
    }
}
